using System;
using System.Reflection;

namespace Avanzis.QueryObjects
{
    public class PersistentPropertyInfo : PersistentPropertyBase
    {       
        private PropertyAttribute propertyAttribute;       
        private String databaseField;

        protected PersistentPropertyInfo()
        {
        }

        public PersistentPropertyInfo(PropertyInfo propertyInfo, PropertyAttribute propertyAttribute)  : base(propertyInfo, propertyAttribute)
        {
            this.propertyAttribute = propertyAttribute;
        }

        public PropertyAttribute PropertyAttribute
        {
            get { return propertyAttribute; }          
        } 

        /// <summary>
        /// Gets the database field.
        /// </summary>
        /// <value>The database field.</value>
        public string DatabaseField
        {
            get
            {
                if (databaseField == null)
                {
                    if (!string.IsNullOrEmpty(this.PropertyAttribute.Column))
                    {
                        databaseField = this.PropertyAttribute.Column;
                    }
                    else
                    {
                        databaseField = this.PropertyInfo.Name;
                    }
                }
                return databaseField;
            }
        }       
        
       

    }
}
